package com.xhh.microfin.dispatch.controller;

import com.xhh.microfin.dispatch.common.utils.R;
import com.xhh.microfin.dispatch.model.consts.ProcessConsts;
import com.xhh.microfin.dispatch.model.vo.CommonCallBackOrderVo;
import com.xhh.microfin.dispatch.model.vo.ResponseVo;
import com.xhh.microfin.dispatch.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 003035
 * @Date: 2019/1/16
 */
@RestController
@RequestMapping("callback")
public class CallBackController {

    @Autowired
    private OrderService orderService;


    /**
     * @api {post} /callback/riskCallback  风控回调
     * @apiName RiskCallback
     * @apiGroup CallBack
     * @apiDescription 风控系统处理结果回调
     * @apiParam {String} orderSn 订单编号
     * @apiParam {Number} status 处理结果 1、成功 0、失败
     * @apiSuccessExample {json} Success-Response:
     * {
     * "status": 1,
     * "message": "success",
     * "data": null
     * }
     * @apiErrorExample {json} Error-Response:
     * {
     * "status":0,
     * "message":"系统异常"
     * }
     */
    @PostMapping("riskCallback")
    public R riskCallback(@RequestBody CommonCallBackOrderVo commonCallBackOrderVo) {

        orderService.callBack(commonCallBackOrderVo.getOrderSn(),ProcessConsts.RISK,commonCallBackOrderVo.getStatus());
        return R.ok();
    }

    /**
     * @api {post} /callback/adminCallback 审批回调
     * @apiName adminCallback
     * @apiGroup CallBack
     * @apiDescription 审批系统处理结果回调
     * @apiParam {String} orderSn 订单编号
     * @apiParam {Number} status 处理结果 1、成功 0、失败
     * @apiSuccessExample {json} Success-Response:
     * {
     * "status": 1,
     * "message": "success",
     * "data": null
     * }
     * @apiErrorExample {json} Error-Response:
     * {
     * "status":0,
     * "message":"系统异常"
     * }
     */
    @PostMapping("adminCallback")
    public String adminCallback(@RequestBody CommonCallBackOrderVo commonCallBackOrderVo) {
        orderService.callBack(commonCallBackOrderVo.getOrderSn(),ProcessConsts.ADMIN,commonCallBackOrderVo.getStatus());
        return new ResponseVo().toString();
    }
}
